
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台管理</title>
<link href="__PUBLIC__/ht/css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="__PUBLIC__/ht/js/jquery.js"></script>
<script type="text/javascript" src="__PUBLIC__/ht/js/action.js"></script>
<style>
.dx1{float:left; margin-left: 17px; margin-bottom:10px; }
.dx2{color:#090; font-size:16px;  border-bottom:1px solid #CCC; width:100% !important; padding-bottom:8px;}
.dx3{width:120px; margin:5px auto; border-radius: 2px; border: 1px solid #b9c9d6; display:block;}
.dx4{border-bottom:1px solid #eee; padding-top:5px; width:100%;}
</style>
</head>
<body>

<div class="aaa_pts_show_1">【 产品管理 】</div>

<div class="aaa_pts_show_2">
    <div>
       <div class="aaa_pts_4"><a href="{:U('set_attr')}?pid={$pro_id}">设置规格</a></div>
       <div class="aaa_pts_4"><a href="{:U('pro_guige')}?pid={$pro_id}">规格管理</a></div>
       <div class="aaa_pts_4"><a href="{:U('pro_attr')}?pid={$pro_id}">属性组合管理</a></div>
    </div>
    <div class="aaa_pts_3">
      <ul id="ul" class="aaa_pts_5">
         <li class="product"><div class="d1 dx2">属性规格信息</div></li>
         <volist name="guige_list" id="v">
         <li>
            <div class="d1">{$v.attr_name}:</div>
            <input type="hidden" name="attr_id" id="attr_id" value="{$v.attr_id}">
            <div>
              <volist name="v['guige_list']" id="vs">
                <input type="hidden" name="guige_id" id="guige_id" value="{$vs.id}" />
                <label style="font-weight:bold;">【{$vs.name}】</label>
              </volist>
            </div>
         </li>
         </volist>
         <li><input type="button" id="button" style="width:120px;height:30px;" value="更新属性组合" class="aaa_pts_web_3" onclick="update_attr();">
          <input type="hidden" id="pro_id" name="pro_id" value="<?php echo $pro_id; ?>">
          <span style="color:red;font-size:12px;">&nbsp;* 若有产品规格已删除，请点击这里更新组合信息</span>
         </li>
      </ul>
    </div>
    <div class="aaa_pts_3"><span style="color:red">备注：若有产品属性组合不需要或库存不足，请将对应库存设置为0</span>
      <form name='form' action="{:U('ProAttribute/save_attr')}"  method="post" onsubmit="return ac_from();">
      <table class="pro_3">
         <tr class="tr_1">
           <td style="width:100px;">组合ID</td>
           <td>属性组合名称</td>
           <td style="width:300px;">价格/元<span style="color:red;">(双击修改)</span></td>
           <td style="width:300px;">库存<span style="color:red;">(双击修改)</span></td>
         </tr>
         <tbody id="news_option">
         <!-- 遍历 -->
          <volist name="attr_list" id="v" empty="产品没有属性">
           <tr>
            <td>{$v.id}</td>
            <td><span>{$v.guige_name}</span></td>
            <td id="td_{$v.id}"><span ondblclick="upprice({$v.id},this);">{$v.price}</span></td>
            <td id="tds_{$v.id}"><span ondblclick="upstock({$v.id},this);">{$v.stock}</span></td>
           </tr>
          </volist>
         <!-- 遍历 -->
         </tbody>
      </table>
      </form>    
    </div>
</div>
<script type="text/javascript">
  function upprice(id,obj){
    var price = $(obj).html();
    $(obj).html('<input type="text" name="price_'+id+'" id="price_'+id+'" value="'+price+'" onblur="ajax_upprice('+price+','+id+');">');
    $(obj).children().focus();
    $(obj).removeAttr('ondblclick');
  }

  function upstock(id,obj){
    var stock = $(obj).html();
    $(obj).html('<input type="text" name="stock_'+id+'" id="stock_'+id+'" value="'+stock+'" onblur="ajax_upstock('+stock+','+id+');">');
    $(obj).children().focus();
    $(obj).removeAttr('ondblclick');
  }

  //ajax修改价格
  function ajax_upprice(price,id){
    var up_price = document.getElementById('price_'+id).value;
    if (price==up_price) {
      $('#td_'+id).html('<span ondblclick="upprice('+id+',this);">'+price.toFixed(2)+'</span>');
      return ;
    };

    //ajax
    $.post('{:U("ajax_up")}',{pro_id:'{$pro_id}',vals:up_price,id:id,type:'pro_price'},function(data){
      if (data.status==1) {
        $('#td_'+id).html('<span ondblclick="upprice('+id+',this);">'+up_price+'</span>');
      }else{
        alert(data.err);
        return false;
      }
    },'json');
  }

  //ajax修改库存
  function ajax_upstock(stock,id){
    var up_stock = document.getElementById('stock_'+id).value;
    if (stock==up_stock) {
      $('#tds_'+id).html('<span ondblclick="upstock('+id+',this);">'+stock+'</span>');
      return ;
    };

    //ajax
    $.post('{:U("ajax_up")}',{pro_id:'{$pro_id}',vals:up_stock,id:id,type:'pro_stock'},function(data){
      if (data.status==1) {
        $('#tds_'+id).html('<span ondblclick="upstock('+id+',this);">'+up_stock+'</span>');
      }else{
        alert(data.err);
        return false;
      }
    },'json');
  }

  //更新组合信息
  function update_attr(){
    var pro_id = $('#pro_id').val();
    $.post('{:U("update_attr")}',{pro_id:pro_id},function(data){
      if (data.status==1) {
        window.location.reload();
      }else{
        alert(data.err);
        return false;
      }
    });
  };
</script>
</body>
</html>
